import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [
    {
        path: '/',
        component: () => import('../view/home.vue'),
        children: [

            { path: 'users', component: () => import('../view/users.vue') },


        ],
    },
    {
        path: '/home',
        component: () => import('../view/home.vue')

    },
    {
        path: '/login',
        component: () => import('../view/index.vue')
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});
//导航守卫
router.beforeEach((to, from, next) => {
    if (to.path == '/home' || to.path == '/') {
        if (!localStorage.getItem('userinfo')) {
            next('/login')
        }
    }
    if (to.path == '/login') {
        if (localStorage.getItem('userinfo')) {
            next(from)
        }
    }
    next()

})
//导出
export default router